<template>
  <HomePanel title="新鲜好物" subTitle="新鲜出炉 品质靠谱" ref="target">
    <template v-slot:right>
      <XtxMore />
    </template>
    <template v-slot:default>
      <ul class="goods-list" v-if="newData.length">
        <!-- 有数据时 -->
        <li v-for="item in newData" :key="item.id">
          <RouterLink to="/">
            <img :src="item.picture" alt="" />
            <p class="name ellipsis">{{ item.name }}</p>
            <p class="price">&yen;{{ item.price }}</p>
          </RouterLink>
        </li>
      </ul>
      <!-- 没有数据时 -->
      <transition name="fade">
        <HomeSkeleton v-if="newData.length === 0" />
      </transition>
    </template>
  </HomePanel>
</template>
<script>
import HomePanel from "../currency/HomePanel";
import HomeSkeleton from "../currency/HomeSkeleton";
import useLazyData from "../../hooks/useLazyData";
import { getFreshStuff } from "../../api/home";
// import { ref } from "vue";

export default {
  name: "HomeNew",
  components: { HomePanel, HomeSkeleton },
  setup() {
    let { target, result: newData } = useLazyData(getFreshStuff());
    // console.log(newData);

    return { target, newData };
  },
};
</script>

<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;

  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();

    img {
      width: 306px;
      height: 306px;
    }

    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }

    .price {
      color: @priceColor;
    }
  }
}

.home-skeleton {
  top: 115px;
}
</style>
